﻿--local frame = CreateFrame("Frame");
--frame:SetScript("OnEvent", MyAddOn_OnEvent);
--frame:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE");

CAlert_EventsTable = {
	"PARTY_MEMBERS_CHANGED",
	"PLAYER_REGEN_ENABLED",
	"PLAYER_REGEN_DISABLED",
	--"CHAT_MSG_CHANNEL_NOTICE",
	"PLAYER_LOGIN",

	-- Messages to measure how much damage is dealt.
	"CHAT_MSG_COMBAT_SELF_HITS",	-- Melee you do on things.
	"CHAT_MSG_COMBAT_PET_HITS",		-- Melee your pets do.
	"CHAT_MSG_COMBAT_PARTY_HITS",	-- Melee done by part.
	"CHAT_MSG_COMBAT_FRIENDLYPLAYER_HITS",	-- Melee done by friendlies.
	"CHAT_MSG_SPELL_SELF_DAMAGE",	-- Your spells that damage other things.
	"CHAT_MSG_SPELL_PET_DAMAGE",
	"CHAT_MSG_SPELL_PARTY_DAMAGE",	-- Party member's spell hits.
	"CHAT_MSG_SPELL_FRIENDLYPLAYER_DAMAGE", -- Spells other people cast on things.
	"CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE", -- Blah suffers # Arcane damage from #'s/your Spell.  Works on self, party, friendly.
	"CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_DAMAGE",
	"CHAT_MSG_SPELL_DAMAGESHIELDS_ON_SELF",		-- Thorns on self.
	"CHAT_MSG_SPELL_DAMAGESHIELDS_ON_OTHERS",	-- Thorns on others.

	-- Messages to measure healing done and received.
	"CHAT_MSG_SPELL_SELF_BUFF",
	"CHAT_MSG_SPELL_PARTY_BUFF",
	"CHAT_MSG_SPELL_FRIENDLYPLAYER_BUFF",
	"CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS",
	"CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS",
	"CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS",
	"CHAT_MSG_SPELL_HOSTILEPLAYER_BUFF",
	"CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS",

	-- Messages to measure damage taken.
	"CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS",
	--"CHAT_MSG_COMBAT_CREATURE_VS_SELF_MISSES",
	"CHAT_MSG_COMBAT_CREATURE_VS_PARTY_HITS",
	--"CHAT_MSG_COMBAT_CREATURE_VS_PARTY_MISSES",
	"CHAT_MSG_COMBAT_CREATURE_VS_CREATURE_HITS",
	--"CHAT_MSG_COMBAT_CREATURE_VS_CREATURE_MISSES",
	"CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE",
	"CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE",
	"CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE",
	"CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE",
	"CHAT_MSG_SPELL_PERIODIC_PARTY_DAMAGE",
	"CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_DAMAGE",
	-- The HOSTILEPLAYER ones are for dueling and pvp.
	"CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS",
	"CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE",
	"CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_DAMAGE",
}

function CAlert_print(text)
	local msgbox = getglobal("CAlertMessageFrame");
	msgbox:AddMessage(text);
end

function CAlert_OnLoad()
	for index, event in ipairs(CAlert_EventsTable) do
		this:RegisterEvent(event);
	end
end

function CAlert_OnEvent()
  
	if arg1 then
		for who in string.gmatch(arg1, "(.)獲得了暗影披風的效果。") do							
			CAlert_print(event..":"..arg1);		
			SendAddonMessage("NECB", ".countsec 5 "..who.."的暗影披風解除", "WHISPER", UnitName("player"));	
		end
		for who in string.gmatch(arg1, "你獲得了暗影冥思") do							
			CAlert_print(event..":"..arg1);		
		end
	end
  
--[[	string eventstr = event;
	if arg1 then
		eventstr = eventstr .." : ".. arg1;
		end  
	CAlert_print(eventstr);
	
    if(event=="CHAT_MSG_SPELL_SELF_DAMAGE") then		
		
	elseif(event=="UNIT_SPELLCAST_SUCCEEDED") then		
		if arg1 then
			msgbox:AddMessage("unit:"..arg1.."/spell:"..arg2.."/rank:"..arg3);
		end
		
	elseif(event=="CHAT_MSG_SPELL_HOSTILEPLAYER_BUFF") then
		if(arg1) then
			
		--獲得了聖盾術的效果。
		暗影冥思
			for who in string.gmatch(arg1, "(.)獲得了暗影披風的效果。") do						
				SendAddonMessage("NECB", ".countsec 5 "..who.."的暗影披風解除", "WHISPER", UnitName("player"));				
			end
			
			for who in string.gmatch(arg1, "(.)獲得了夜幕的效果。") do						
				SendAddonMessage("NECB", ".countsec 5 "..who.."的夜幕解除", "WHISPER", UnitName("player"));				
			end
		end
	
	elseif(event=="CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS") then		
	
	end
]]	
end


function CALertMessageFrame_OnMouseWheel(self, delta)
	--[[if not value then
		return;
	end]]
	local frame = getglobal("CAlertMessageFrame");
	if ( delta > 0 ) then
		frame:ScrollUp();
	elseif ( delta < 0 ) then
		if IsShiftKeyDown() then frame:ScrollToBottom()
		else frame:ScrollDown();
		end
	end
	
end
